/*
弹出提示框逻辑处理
*/
cc.Class({
    extends: cc.Component,

    properties: {
        parent:{
            default:null,
            type:cc.Node
        },
        type:0, //0->tipsBox;1->loadingNode;more:
        isInit:false,
    },

    onLoad: function () {

    },

    onInit:function(){
        if(this.type)
        {
            this.loadingAni = this.node.getChildByName("loadingAni");
            this.tipsLabel = this.node.getChildByName("tipsLabel").getComponent("cc.Label");
            return;
        }
        this.okCallFunc = -1;
        this.cancelCallFunc = -1;
        this.tipsLabel = this.node.getChildByName("tipsLabel").getComponent("cc.Label");
        this.btnOK = this.node.getChildByName("btnOK");
        this.btnCancel = this.node.getChildByName("btnCancel");
        this.isInit = true;
    },

    btnOKClick:function(){
        if(this.okCallFunc == -1)
            this.hideLayer();
        else
            this.okCallFunc();
    },

    btnCancelClick:function(){
        if(this.okCallFunc == -1)
            this.hideLayer();
        else
            this.cancelCallFunc();
    },

    resetTips:function(){
        this.okCallFunc = -1;
        this.cancelCallFunc = -1;
    },

    setTipsType:function(type,curStr,okCall,cancelCall){//type:0->just label;1->label+ok;2->label+ok+cancel;
        if(this.isInit == false)
            this.onInit();
        this.resetTips();
        this.tipsLabel.string = curStr;
        if(type == 0)
        {
            this.btnOK.active = false;
            this.btnCancel.active = false;
        }
        if(type == 1)
        {
            this.btnOK.active = true;
            this.btnCancel.active = false;
            this.btnOK.x = 0;
        }
        if(type == 2)
        {
            this.btnOK.active = true;
            this.btnCancel.active = true;
            this.btnOK.x = -110;
            this.btnCancel.x = 110;
        }
        if(okCall)
            this.okCallFunc = okCall;
        if(cancelCall)
            this.cancelCallFunc = cancelCall;

        this.node.active = true;
    },

    showLayer:function(type,curStr,okCall,cancelCall){
        if(this.isInit == false)
            this.onInit();
        if(this.type){
            if(type && curStr)
                this.tipsLabel.string = curStr;
            else
                this.tipsLabel.string = "正在拼命重连中......";
            this.loadingAni.runAction(cc.repeatForever(cc.rotateBy(1,-360)));
        }else{
            this.setTipsType(type,curStr,okCall,cancelCall);
        }
        this.node.active = true;
    },

    hideLayer:function(){
        if(this.type)
            this.loadingAni.stopAllActions();
        this.node.active = false;
    },
});
